package com.atguigu.yygh.hosp.controler;

import com.atguigu.yygh.cmn.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalControler {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private ScheduleService scheduleService;
    @ApiOperation(value = "分页查询")
    @GetMapping("/list/{page}/{limit}")
    public Result<Page> pageResult(@PathVariable Integer page,
                                   @PathVariable Integer limit,
                                   HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page1=hospitalService.selectPage(page,limit,hospitalQueryVo);
        return  Result.ok(page1);
    }
    @ApiOperation(value = "更新上线状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result lock(@PathVariable String id,
                       @PathVariable Integer status){
        System.out.println("进入接口");
        hospitalService.updateStatus(id,status);
        return  Result.ok();
    }
    @ApiOperation(value = "获取医院详情")
    @GetMapping("showHospDetaiil/{id}")
    public Result show(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable String id) {
        Map<String,Object> map= hospitalService.getHospById(id);
        return Result.ok(map);
    }

//    1 根据编号查询该医院所有的科室列表
//    2 所有科室按照树形结构显示
@ApiOperation(value = "获取可预约排班数据")
@GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
public Result getBookingSchedule(
        @ApiParam(name = "page", value = "当前页码", required = true)
        @PathVariable Integer page,
        @ApiParam(name = "limit", value = "每页记录数", required = true)
        @PathVariable Integer limit,
        @ApiParam(name = "hoscode", value = "医院code", required = true)
        @PathVariable String hoscode,
        @ApiParam(name = "depcode", value = "科室code", required = true)
        @PathVariable String depcode) {
    return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
}

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable String scheduleId) {
        return Result.ok(scheduleService.getById(scheduleId));
    }
}
